/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : HomonymHandler.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Dec 16, 2008       Raghu Sarraff			       Created
 */
package lwf.handler.english;

import java.util.List;
import java.util.Map;

import net.lwf.handler.util.ImageHtml;

import lwf.factory.PropertyReader;

/**
 * Type the class description here
 *  
 */
public class HomonymHandler extends WordHandler {
	
	private boolean headingdisplay = false;

	public HomonymHandler(int start, int end, int level) {
		init(start, end, level);
	}
	
	public HomonymHandler(int start, int end) {
		init(start, end, 0);
	}
	
	private void init(int start, int end, int level) {
		Map maphomonyms = (Map) PropertyReader.getInstance().getHomonyms();
		List lsthomonyms = null;
		while(lsthomonyms == null) {
			lsthomonyms = (List) maphomonyms.get(String.valueOf(level));
			level = level - 1;
		}
		setDisplayData(start, end, lsthomonyms);
	}
  
  protected String processRowData(Object obj) {
  	String data = (String) obj;
  	
  	StringBuffer sbPData = new StringBuffer();
  	sbPData.append("<table border=\"0\" width=\"100%\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\">");
  	    if(!headingdisplay) {
  		    sbPData.append("<tr>");
		        sbPData.append("<td width=\"10%\">&nbsp;</td>");
		        sbPData.append("<td width=\"75%\" class=\"tableHeader\" nowrap>Homonyms</td>");
		        sbPData.append("<td width=\"15%\"> &nbsp; </td>");
	        sbPData.append("</tr>");
	        headingdisplay = true;
  	    }
	    sbPData.append("<tr>");
	        sbPData.append("<td width=\"10%\">");
		        sbPData.append(ImageHtml.getBulletImage(1));
	        sbPData.append("</td>");
	        sbPData.append("<td width=\"75%\" class=\"dataleft\" >");
            	sbPData.append(data);
            sbPData.append("</td>");		        
	        sbPData.append("<td width=\"15%\"> &nbsp; </td>");
	    sbPData.append("</tr>");                
      sbPData.append("</table>");
      return sbPData.toString();
  } //processRowData

}

